package com.syni.mdd.yhd.common.all.service;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsUserVideoDao;
import com.syni.mdd.yhd.common.all.dao.jpa.BmsbusinessDao;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsUserVideo;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @className BmsUserOperationLogService
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class BmsUserVideoService extends BaseService<BmsUserVideo, Integer> {

    @Autowired
    BmsUserVideoDao bmsUserVideoDao;

    @Override
    public BmsUserVideoDao getBaseDao() {
        return bmsUserVideoDao;
    }

    public List<BmsUserVideo> getByVideoIds(Set<Integer> videoIds){
        return bmsUserVideoDao.findByBmsVideoIdIn(videoIds);
    }

    public List<BmsUserVideo> getByUserId(Integer id){
        return bmsUserVideoDao.findByUserId(id);
    }

    public BmsUserVideo getByVideoId(Integer videoId){
        return bmsUserVideoDao.findByBmsVideoId(videoId);
    }

    public Integer findUserTotalRelease(Integer userId) {
        Integer ret = 0;
        Set<Integer> fromOrigins = new HashSet<>();
        fromOrigins.add(Constants.ADMIN_CLIENT);
        fromOrigins.add(Constants.USER_CLIENT);
        Map<String,Object> resultMap = bmsUserVideoDao.selfFindUserVideo(userId,fromOrigins);
        if(resultMap != null && resultMap.size() > 0){
            ret = Integer.parseInt(resultMap.get("num").toString());
        }
        return ret;
    }
}
